cmake_minimum_required(VERSION 3.16)

project(sqlserver)

if(NOT CMAKE_BUILD_TYPE)
	set(CMAKE_BUILD_TYPE "debug") # 默认debug模式
endif()

if(NOT MUDUO_PATH)
	set(MUDUO_PATH "/home/$ENV{USER}/build/${CMAKE_BUILD_TYPE}-install-cpp11")
endif()

SET(CXX_FLAGS
-g
-Wall #大部分警告
-Wextra #一些额外的警告
# -Werror # 当出现警告时转变为错误, 停止编译
-Wconversion # 一些可能改变值的隐式转换, 给出警告
-Wno-unused-parameter #函数中出现未使用的参数, 不给出警告
-Wold-style-cast # c风格的变换给出警告
-Woverloaded-virtual # 如果函数的声明隐藏住了基类的虚函数, 就给出警告
-Wpointer-arith # 对函数指针或者void*类型的指针进行算术操作时给出警告
-Wshadow # 当一个局部变量掩盖了另一个局部变量时或全局变量时给出警告
-Wwrite-strings # 规定字符串常量的类型是const char[length],因此把这样的地址复制给non-const char*将产生警告，同时避免向字符串常量写入的行为
)

string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CXX_FLAGS}")

set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CXX_DEBUG "-O0") #debug模式不优化
set(CMAKE_CXX_RELEASE "-O2 -finline-limit=1000 -DNDEBUG") #O2优化,对伪指令数超过1000的函数,编译程序不进行内联展开, 关闭所有assert(),2.8以上版本自带-DNDEBUG

find_path(Muduo_INCLUDE_DIR muduo "${MUDUO_PATH}/include")
find_path(Muduo_LIBRARY_DIR libmuduo_net.a "${MUDUO_PATH}/lib")
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${Muduo_LIBRARY_DIR})
message(STATUS ${Muduo_INCLUDE_DIR})
message(STATUS ${Muduo_LIBRARY_DIR})

include_directories(${Muduo_INCLUDE_DIR})
find_library(muduo_base muduo_base)
find_library(muduo_net muduo_net)
message(STATUS ${muduo_base})
message(STATUS ${muduo_net})

find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

include_directories(${PROJECT_SOURCE_DIR})

# add_executable(test_pool ../src/test_pool.cpp ../src/SqlConnection.cpp)
# target_link_libraries(test_pool pthread jsoncpp mysqlclient)

# add_executable(parase_json ../src/parase_json.cpp)
# target_link_libraries(parase_json jsoncpp)

add_executable(main ../src/main.cpp ../src/SqlServer.cpp ../src/SqlConnection.cpp)
target_link_libraries(main ${muduo_net} ${muduo_base} pthread jsoncpp mysqlclient rt)